<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('扣款单')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
    <style type="text/css">
        .la{text-align:left;}
        .textBox{text-align:right;}
    </style>
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="materialLeadForm" th:action="@{/materialLead/list}" class="form-inline">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3">
                            <label>物料号: </label>
                            <input type="text" name="materialCode"/>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>工厂：</label>
                                <input type="text" name="werks"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>物料描述：</label>
                                <input type="text" name="materialDesc"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>领用人：</label>
                                <input type="text" name="leadMan"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>发货是否完成：</label>
                                <select id="fhwc" name="fhwc" type="text">
                                    <option value="0">完成</option>
                                    <option  value="1" selected="selected">未完成</option>
                                    <option value="2">全部</option>
                                </select>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>领用时间开始：</label>
                                <input type="text" id="leadS" name="leadS" autocomplete="off"/>
                            </div>
                        </li>

                        <li class="col-sm-3">
                            <div>
                                <label>领用时间结束：</label>
                                <input type="text" id="leadE" name="leadE" autocomplete="off"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>发货人：</label>
                                <input type="text" name="retrunman"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>领用部门：</label>
                                <input type="text" sysDict="LYBM" name="leadDept"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <button id="materialLeadSearchBtn" type="button"
                                    class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索
                            </button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置
                            </button>
                            <button id="materialLeadAdvancedSearch" type="button"
                                    class="btn btn-primary btn-rounded btn-sm" style="display: none"><i
                                    class="fa fa-caret-down"></i>&nbsp;高级搜索
                            </button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="materialLeadToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="toCancel()">
                    <i class="fa fa-edit"></i> 取消
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toReturn()">
                    <i class="fa fa-edit"></i> 发货
                </a>
            </div>
            <table id="materialLead" data-mobile-responsive="true">
            </table>
        </div>
    </div>
</div>
</div>
<!-- 引入公共js -->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<!-- Page-Level Scripts -->
<script type="text/javascript">
    //面向对象
    var searcherBS = Searcher.createBS('#materialLead',
        [
            {checkbox: true},
            {title: '物料号', field: 'materialCode'},
            {title: '物料描述', field: 'materialDesc'},
            {title: '工厂', field: 'werks'},
            {title: '账号', field: 'account'},
            {title: '领用人', field: 'leadMan'},
            {title: '领用部门', field: 'leadDept'},
            {title: '领用数量', field: 'leadnum'},
            {title: '领用时间', field: 'createtime'},
            {title: '预计归还时间', field: 'returntime'},
            {title: '实际发货时间', field: 'actualtime'},
            {title: '发货人', field: 'retrunman'},
            {title: '发货仓库', field: 'returnDept'},
            {title: '发货数量', field: 'returnNum'}
        ]
    );

    //刷新数据
    function refresh() {
        searcherBS.refresh();
    }

    // 初始化时间插件
    laydate.render({elem: '#leadS'});
    laydate.render({elem: '#leadE'});
    initDictDataSel();//初始化所有字典数据

    /**
     * @Description: 跳转到归还页面
     */
    function toReturn() {
        //获取工厂id
        var rowDatas = searcherBS.getSelectedRows("materialLeadId");
        var returnNum = searcherBS.getSelectedRows("returnNum");
        var leadnum = searcherBS.getSelectedRows("leadnum");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        if (parseInt(returnNum) >= parseInt(leadnum)) {
            Dialog.errorMsg("已经归还完成,无法继续发货");
            return;
        }
        var index = Dialog.openUrl("物料发货", ctxPath + '/materialFactory/toReturn/' + rowDatas,
            {
                area: ['900px', '700px'],
                maxmin: true,
                end: function () {
                }
            });
        layer.full(index)
    }
    /**
     * @Description:  跳转到取消方法
     */
    function  toCancel() {
        var materialLeadId = searcherBS.getSelectedRows("materialLeadId");
        if (materialLeadId.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        Page.ajaxPOST(ctxPath + "/materialLead/toCancel",{materialLeadId:materialLeadId}, function () {
            Dialog.msg("操作成功", function () {
                searcherBS.refresh();
            });
        },{"loadingMsg" : "正在往服务器提交数据……"});

    }

</script>
</body>
</html>